<%--
  - Copyright 2011 Angel Sanadinov
  -
  - This file is part of VBox WMI.
  -
  - VBox WMI is free software: you can redistribute it and/or modify
  - it under the terms of the GNU General Public License as published by
  - the Free Software Foundation, either version 3 of the License, or
  - (at your option) any later version.
  -
  - VBox WMI is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  - GNU General Public License for more details.
  -
  - You should have received a copy of the GNU General Public License
  - along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
  --%>

<%@page import="Utilities.Functions"%>
<%@page import="Utilities.UIFunctions"%>
<%@page import="Beans.Requests.DataRetrieval.SystemDataRetrievalRequest"%>
<%@page import="Utilities.ParameterNames"%>
<%@page import="Utilities.ParameterNames.Service"%>
<%@page import="Utilities.Constants"%>
<%@page import="Utilities.Constants.SendingRequestResult"%>
<%@page import="Beans.Responses.DataRetrievalComponents.SystemDataComponent"%>
<%@page import="Beans.Responses.DataRetrievalResponse"%>
<%@page import="Managers.Utilities.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%@taglib uri="/WEB-INF/tlds/pagePrintingTags.tld" prefix="p"%>
<%
    //retrieves user data from the session
    User userSessionData = (User)session.getAttribute(ParameterNames.SESSION_USER_OBJECT);

    //data retrieval request and response objects
    SystemDataRetrievalRequest dataRequest = null;
    DataRetrievalResponse<SystemDataComponent> data = null;

    //attemtps to retrieve the server ID
    int viewSystemId = Constants.INVALID_SERVER_ID;
    try
    {
        viewSystemId = Integer.parseInt(request.getParameter("id"));
    }
    catch(NumberFormatException e)
    {
        viewSystemId = userSessionData.getCurrentServerId();
    }

    //checks the validity of the server ID and builds the request
    if(Functions.isServerIdValid(viewSystemId))
        dataRequest = new SystemDataRetrievalRequest(userSessionData.getUserData().getUserId(), viewSystemId);
    else
        ;

    //attempts to send the request and retrieves the response
    if(UIFunctions.sendServiceRequest(request, response, dataRequest, Service.DATA_RETRIEVAL) == SendingRequestResult.OK)
        data = (DataRetrievalResponse<SystemDataComponent>)UIFunctions.retrieveServiceResponse(request, Service.DATA_RETRIEVAL);
    else
        ;
%>
<p:printPageHeader pageName="System Data" pageId="pageServers" userSessionData="<%= userSessionData %>"/>
        <p:printSystem data="<%= data %>"/>
<p:printPageFooter/>
